<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/4/8
 * Time: 14:33
 */
namespace app\admin\controller;
use think\Db;
class Consumer extends Base {

    /***
     * @return mixed|\think\response\Json
     * 首页
     */
    public function index(){
        if(request()->isAjax ()){
            $params = input('param.');
            $where = array();
            //关键字
            if(isset($params['keyword']) && $params['keyword'] != ''){
                $keyword = $params['keyword'];
                $where['a.user_integral'] = array('like',"%$keyword%");
            }
            if(isset($params['coupon_name']) && $params['coupon_name'] != ''){
                $keyword1 = $params['coupon_name'];
                $where['a.user_id|a.user_username|a.user_phone'] = array('like',"%$keyword1%");
            }
            if(isset($params['province']) && $params['province'] != ''){
                $where['a.user_sheng'] =$params['province'] ;
            }
            if(isset($params['city']) && $params['city'] != ''){
                $where['a.user_shi'] = $params['city'];
            }
            if(isset($params['district']) && $params['district'] != ''){
                $where['a.user_qu'] = $params['district'];
            }
            //状态
            if(isset($params['user_type']) && $params['user_type'] != ''){
                $where['user_type'] = $params['user_type'];
            }
            //学校
            if(isset($params['user_school']) && $params['user_school'] != ''){
                $where['a.user_school'] = $params['user_school'];
            }
            //学校
            if(isset($params['up_honor']) && $params['up_honor'] != ''){
                $honor = ','.$params['up_honor'].',';
                $where['a.user_honor'] = array('like',"%$honor%");
            }
            //学校
            if(isset($params['level']) && $params['level'] != ''){

                $where['a.user_level'] = $params['level'];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('u_user')->alias('a')
                ->join('up_area ua','ua.district_id = a.user_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.user_sheng','left')
                ->join('up_area ua2','ua2.district_id = a.user_sheng','left')
                ->join('up_school us','us.school_id = a.user_school','left')
                ->where($where)->count();// 获取总条数
            //用于全部导出
            $count2 = Db::name('u_user')->alias('a')
                ->join('up_area ua','ua.district_id = a.user_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.user_sheng','left')
                ->join('up_area ua2','ua2.district_id = a.user_sheng','left')
                ->join('up_school us','us.school_id = a.user_school','left')
                ->where($where)
                ->column('user_id');
            $lists = Db::name('u_user')->alias('a')
                ->join('up_area ua','ua.district_id = a.user_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.user_shi','left')
                ->join('up_area ua2','ua2.district_id = a.user_qu','left')
                ->join('up_school us','us.school_id = a.user_school','left')
                ->where($where)
                ->field('a.user_level,a.user_image,a.user_type,a.user_nickname,a.user_id,us.school_name,a.user_time,
                a.user_id,a.user_username,a.user_phone,
                ua.district,ua1.district as district1,ua2.district as district2,a.user_honor, a.user_status')
                ->page($Nowpage,$limits)
                ->order('user_time desc')
                ->select();

            foreach ($lists as $key=>&$vo){
                $user_honor = trim($vo['user_honor'],',');
                $name = Db::table('up_honor')->where('id','IN',$user_honor)->column('name');
                $level = Db::table('up_exp_level')->where('el_id',$vo['user_level'])->value('el_name');
                $vo['name'] = implode(',',$name);
                $vo['level'] = $level;
                $aa = array();
                $bb = array();
                if($vo['user_type']==1){
                    $vo['user_type_a'] = '学生';
                }
                if($vo['user_type']==2){
                    $vo['user_type_a'] = '老师';
                }
                $vo['address'] = $vo['district'].$vo['district1'].$vo['district2'];
                $info = Db::table('up_grade_class')->alias('a')
                    ->join('up_grade ug','ug.grade_id = a.gs_grade_id','left')
                    ->join('up_class uc','uc.class_id = a.gs_class_id','left')
                    ->field('ug.grade_name,uc.class_name')
                    ->where('a.gs_user_id',$vo['user_id'])
                    ->select();
                foreach ($info as $key1=>&$vo1){
                    $aa[] = $vo1['grade_name'];
                    $bb[] = $vo1['class_name'];
                }
                $vo['info1'] = implode(',',$aa);
                $vo['info2'] = implode(',',$bb);
            }
            $str = '';
            if($count2){
                $str = implode($count2,',');
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'count2' => $str, 'data' => $lists]);
        }
        $where1['school_status']  = 1;
        $where1['school_del']  = 1;
        $info1 = Db::table('up_school')->where($where1)->select();
        $province = Db::table('up_area')->where('level', 1)->select();
        $up_honor = Db::table('up_honor')->select();
        $up_level = Db::table('up_exp_level')->select();
        $this->assign('province', $province);
        $this->assign('up_level', $up_level);
        $this->assign('info1',$info1);
        $this->assign('up_honor',$up_honor);
        if(session('?user_id1')){
            session('user_id1',null);
        }
        return $this->fetch();
    }

    /***
     * 冻结
     */
    public function frozen(){
        $ids = input('ids');
        $num = input('num');
        if($ids == ''){
            return json(['code' => 100, 'msg' => '请选择数据']);
        }
        $status = Db::table('up_u_user')->where('user_id', 'IN', $ids)->column('user_status');
        if($num == 3){//冻结
            if(in_array(3, $status)){
                return json(['code' => 100, 'msg' => '所选数据中含有已冻结的用户，请重新选择']);
            }
        }
        $res = Db::table('up_u_user')->where('user_id', 'IN', $ids)->setField('user_status', $num);
        if($res){
            return json(['code' => 200, 'msg' => "操作成功"]);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    /***
     * 解冻
     */
    public function thaw(){
        $ids = input('ids');
        $num = input('num');
        if($ids == ''){
            return json(['code' => 100, 'msg' => '请选择数据']);
        }
        $status = Db::table('up_u_user')->where('user_id', 'IN', $ids)->column('user_status');
        if($num == 1){//冻结
            if(in_array(1, $status)){
                return json(['code' => 100, 'msg' => '所选数据中含有已解冻的用户，请重新选择']);
            }
        }
        $res = Db::table('up_u_user')->where('user_id', 'IN', $ids)->setField('user_status', $num);
        if($res){
            $templateid = config('yzx')['templ'];
            $phone = Db::table('up_u_user')->where('user_id', 'IN', $ids)->column('user_phone');
//            try{
                foreach($phone as $k => $v){
                    YzxSms($templateid, '', $v, '');//提示
                }
//            }catch(\Exception $e){
        
//            }
            return json(['code' => 200, 'msg' => "操作成功"]);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }

    /***
     * 批量导出
     */
    public function excelIn(){
        set_time_limit(0);
        $ids = input('param.ids');
        if($ids == ''){
            return json(['code' => 100, 'msg' => '请选择教师']);
        }
        $where['a.user_id'] = array('IN',$ids);
        $lists = Db::name('u_user')->alias('a')
            ->join('up_area ua','ua.district_id = a.user_sheng','left')
            ->join('up_area ua1','ua1.district_id = a.user_shi','left')
            ->join('up_area ua2','ua2.district_id = a.user_qu','left')
            ->join('up_school us','us.school_id = a.user_school','left')
            ->where($where)
            ->field('a.user_honor,a.user_image,a.user_type,a.user_nickname,a.user_id,us.school_name,a.user_time,
                a.user_id,a.user_username,a.user_phone,
                ua.district,ua1.district as district1,ua2.district as district2')
            ->select();
        foreach ($lists as $key=>&$vo){
            $user_honor = trim($vo['user_honor'],',');
            $name = Db::table('up_honor')->where('id',$user_honor)->column('name');
            $vo['name'] = implode(',',$name);
            $aa = array();
            $bb = array();
            $vo['user_type_a'] = '';
            if($vo['user_type']==1){
                $vo['user_type_a'] = '学生';
            }
            if($vo['user_type']==2){
                $vo['user_type_a'] = '老师';
            }
            $vo['address'] = $vo['district'].$vo['district1'].$vo['district2'];
            $info = Db::table('up_grade_class')->alias('a')
                ->join('up_grade ug','ug.grade_id = a.gs_grade_id','left')
                ->join('up_class uc','uc.class_id = a.gs_class_id','left')
                ->field('ug.grade_name,uc.class_name')
                ->where('a.gs_user_id',$vo['user_id'])
                ->select();
            foreach ($info as $key1=>&$vo1){
                $aa[] = $vo1['grade_name'];
                $bb[] = $vo1['class_name'];
            }
            $vo['info1'] = implode(',',$aa);
            $vo['info2'] = implode(',',$bb);
            unset($lists[$key]['district']);
            unset($lists[$key]['district1']);
            unset($lists[$key]['district2']);
            unset($lists[$key]['user_image']);
            unset($lists[$key]['user_type']);
        }
        $cellname = [
            ['user_nickname','昵称',20,'LEFT'],
            ['user_id','用户ID',15,'LEFT'],
            ['school_name','认证学校',15,'LEFT'],
            ['user_time','提交时间',15,'LEFT'],
            ['user_username','姓名',15,'LEFT'],
            ['user_phone','手机号码',15,'LEFT'],
            ['user_type_a','身份类别',15,'LEFT'],
            ['address','所在地',15,'LEFT'],
            ['info1','所属年级',15,'LEFT'],
            ['info2','所属班级',30,'LEFT'],
        ];
        $res = exportExcel('平台用户列表','Consumer',$cellname,$lists);
        return json($res);
    }
    /***
     * 基本信息
     */
    public function basis(){
        $id = input('param.id');
        $info = Db::table('up_u_user')->where('user_id',$id)
            ->field('user_gender,user_birthday,user_exp,user_integral,user_school,
                      user_id,user_phone,user_username,user_image,user_gender,user_type,user_sheng,user_shi,user_qu')
            ->find();
        if($info['user_type']==1){
            $info['user_type_name'] = '学生';
        }elseif ($info['user_type']==2){
            $info['user_type_name'] = '老师';
        }
        if($info['user_gender']==1){
            $info['user_gender_name'] = '男';
        }elseif ($info['user_gender']==2){
            $info['user_gender_name'] = '女';
        }
        $user_school = Db::table('up_school')->where('school_id',$info['user_school'])->value('school_name');
        //查询年级，班级
        $info1 = Db::table('up_grade_class')->alias('a')
            ->join('up_grade ug','ug.grade_id = a.gs_grade_id','left')
            ->join('up_class uc','uc.class_id = a.gs_class_id','left')
            ->field('ug.grade_name,uc.class_name')
            ->where('a.gs_user_id',$info['user_id'])
            ->select();
        $aa = array();
        $bb = array();
        foreach ($info1 as $key1=>&$vo1){
            $aa[] = $vo1['grade_name'];
            $bb[] = $vo1['class_name'];
        }
        //查询段位
        $level = Db::table('up_exp_level')
            ->where('el_min','<=',$info['user_exp'])
            ->order('el_level DESC')
            ->find();
        //订单数量
        $count = Db::table('up_order')->where('order_userid',$info['user_id'])->count();
        //对战书籍
        $count1 = Db::table('up_reading_book_pass')->where('rbp_user_id',$info['user_id'])->count();
        //闯关数量
        $count2 = Db::table('up_reading_game_pass')->where('rgp_user_id',$info['user_id'])->count();
        //地区
        $user_sheng = Db::table('up_area')->where('district_id',$info['user_sheng'])->value('district');
        $user_shi = Db::table('up_area')->where('district_id',$info['user_shi'])->value('district');
        $user_qu = Db::table('up_area')->where('district_id',$info['user_qu'])->value('district');
        $info['address'] = $user_sheng.$user_shi.$user_qu;
        $info['info1'] = implode(',',$aa);//年级
        $info['info2'] = implode(',',$bb);//班级
        $info['user_school'] = $user_school;
        $info['level'] = $level['el_name'];
        $info['count'] = $count;//订单数量
        $info['count1'] = $count1;//订单数量
        $info['count2'] = $count2;//订单数量
        $this->assign('user',$info);
        return $this->fetch();
    }
    /***
     * 闯关信息
     */
    public function through(){
        if(request()->isAjax()){
            $where = array();
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $where['a.rhis_user_id'] = input('param.id');
            $count = Db::name('reading_history')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.rhis_user_id')
                ->join('up_area ua','ua.district_id = uuu.user_sheng','left')
                ->join('up_area ua1','ua1.district_id = uuu.user_shi','left')
                ->join('up_area ua2','ua2.district_id = uuu.user_qu','left')
                ->join('up_school us','us.school_id = uuu.user_school','left')
                ->where($where)->count();// 获取总条数
            $lists = Db::name('reading_history')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.rhis_user_id')
                ->join('up_area ua','ua.district_id = uuu.user_sheng','left')
                ->join('up_area ua1','ua1.district_id = uuu.user_shi','left')
                ->join('up_area ua2','ua2.district_id = uuu.user_qu','left')
                ->join('up_school us','us.school_id = uuu.user_school','left')
                ->field('a.*,uuu.user_id,uuu.user_nickname,us.school_name,ua.district,ua1.district as district1,ua2.district as district2')
                ->page($Nowpage,$limits)
                ->where($where)
                ->order('user_status desc')
                ->select();
            foreach ($lists as $key=>&$vo){
                $aa = array();
                $bb = array();
                $vo['address'] = $vo['district'].$vo['district1'].$vo['district2'];
                $info = Db::table('up_grade_class')->alias('a')
                    ->join('up_grade ug','ug.grade_id = a.gs_grade_id','left')
                    ->join('up_class uc','uc.class_id = a.gs_class_id','left')
                    ->field('ug.grade_name,uc.class_name')
                    ->where('a.gs_user_id',$vo['user_id'])
                    ->select();
                foreach ($info as $key1=>&$vo1){
                    $aa[] = $vo1['grade_name'];
                    $bb[] = $vo1['class_name'];
                }
                $vo['info1'] = implode(',',$aa);
                $vo['info2'] = implode(',',$bb);
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch();
    }
    /***
     * 错题本
     */
    public function errorBook(){
        if(request()->isAjax()){
            $where = array();
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $where['a.er_user_id'] = input('param.id');
            $count = Db::name('error_book')->alias('a')
                ->join('up_fight_subject urs','urs.fs_id = a.er_fs_id','left')
//                ->join('up_reading_game urg','urg.rg_id = urs.rs_game_id','left')
                ->where($where)->count();// 获取总条数
            $lists = Db::name('error_book')->alias('a')
                ->join('up_fight_subject urs','urs.fs_id = a.er_fs_id','left')
//                ->join('up_reading_game urg','urg.rg_id = urs.rs_game_id','left')
                ->where($where)
                ->order('er_time desc')
                ->page($Nowpage,$limits)
                ->field('a.*,urs.fs_name')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch('consumer/errorbook');
    }

    /***
     * 收货地址
     */
    public function address(){
        if(request()->isAjax()){
            $where = array();
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $where['a.address_user_id'] = input('param.id');
            $count = Db::name('my_address')->alias('a')
                ->join('up_area ua','ua.district_id = a.address_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.address_shi','left')
                ->join('up_area ua2','ua2.district_id = a.address_qu','left')
                ->where($where)->count();// 获取总条数
            $lists = Db::name('my_address')->alias('a')
                ->join('up_area ua','ua.district_id = a.address_sheng','left')
                ->join('up_area ua1','ua1.district_id = a.address_shi','left')
                ->join('up_area ua2','ua2.district_id = a.address_qu','left')
                ->where($where)
                ->page($Nowpage,$limits)
                ->field('a.*,ua.district,ua1.district as district1,ua2.district as district2')
                ->select();
            foreach ($lists as $key=>&$vo){
                $vo['address'] = $vo['district'].$vo['district1'].$vo['district2'].$vo['address_detail'];
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch();
    }


    /***
     * 优惠卷
     */
    public function coupon(){
        if(request()->isAjax()){
            $where = array();
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $where['a.mc_user_id'] = input('param.id');
            $count = Db::name('my_coupon')->alias('a')
                ->join('up_coupon uc','uc.coupon_id = a.mc_coupon_id')
                ->where($where)->count();// 获取总条数
            $lists = Db::name('my_coupon')->alias('a')
                ->join('up_coupon uc','uc.coupon_id = a.mc_coupon_id')
                ->page($Nowpage,$limits)
                ->where($where)
                ->field('uc.coupon_name,uc.coupon_price,a.*')
                ->select();
            foreach ($lists as $key=>&$vo){
                if($vo['mc_status']==1){
                    $vo['status'] = "未使用";
                }elseif ($vo['mc_status']==2){
                    $vo['status'] = "已使用";
                }elseif ($vo['mc_status']==3){
                    $vo['status'] = "已过期";
                }
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch();
    }

    /***
     * 研学活动
     */
    public function studies(){
        if(request()->isAjax()){
            $where = array();
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $where['a.st_user_id'] = input('param.id');
            $count = Db::name('studies')->alias('a')
                ->join('up_coupon uc','uc.coupon_id = a.st_id','left')
                ->where($where)->count();// 获取总条数
            $lists = Db::name('studies')->alias('a')
                ->join('up_notice un','un.n_id = a.st_id','left')
                ->page($Nowpage,$limits)
                ->field('un.n_money,un.n_title,a.*')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch();
    }

    /***
     * 好友列表
     */
    public function friend(){
        if(request()->isAjax()){
            $where = array();
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $where['a.friend_user_id'] = input('param.id');
            $where['a.friend_status'] = 1;
            $count = Db::name('friend')->alias('a')
                ->where($where)->count();// 获取总条数
            $lists = Db::name('friend')->alias('a')
                ->where($where)
                ->page($Nowpage,$limits)
                ->select();
            foreach ($lists as $key=>&$vo){
               $user_exp = Db::table('up_u_user')->where('user_id',$vo['friend_other_user'])->find();
                if($user_exp['user_gender']==1){
                    $vo['gender'] = '男';
                }else{
                    $vo['gender'] = '女';
                }
                //查询段位
                $level = Db::table('up_exp_level')
                    ->where('el_min','<=',$user_exp['user_exp'])
                    ->order('el_level DESC')
                    ->find();
                $vo['level'] = $level['el_name'];
                $vo['user_username'] = $user_exp['user_username'];
                $vo['user_age'] = $user_exp['user_age'];
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch();
    }

    /***
     * 黑名单列表
     */
    public function black(){
        if(request()->isAjax()){
            $where = array();
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $where['a.friend_user_id'] = input('param.id');
            $where['a.friend_status'] = 4;
            $count = Db::name('friend')->alias('a')
                ->where($where)->count();// 获取总条数
            $lists = Db::name('friend')->alias('a')
                ->where($where)
                ->page($Nowpage,$limits)
                ->select();
            foreach ($lists as $key=>&$vo){
                $user_exp = Db::table('up_u_user')->where('user_id',$vo['friend_other_user'])->find();
                if($user_exp['user_gender']==1){
                    $vo['gender'] = '男';
                }else{
                    $vo['gender'] = '女';
                }
                //查询段位
                $level = Db::table('up_exp_level')
                    ->where('el_min','<=',$user_exp['user_exp'])
                    ->order('el_level DESC')
                    ->find();
                $vo['level'] = $level['el_name'];
                $vo['user_username'] = $user_exp['user_username'];
                $vo['user_age'] = $user_exp['user_age'];
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch();
    }
    /***
     * 收藏列表
     */
    public function like(){
        if(request()->isAjax()){
            $where = array();
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $where['a.like_user_id'] = input('param.id');
            $count = Db::name('my_like')->alias('a')
                ->join('up_goods ug','ug.good_id = a.like_shop_id','left')
                ->where($where)->count();// 获取总条数
            $lists = Db::name('my_like')->alias('a')
                ->join('up_goods ug','ug.good_id = a.like_shop_id','left')
                ->page($Nowpage,$limits)
                ->field('ug.good_name,ug.good_price,ug.good_y_price,ug.good_type,a.*')
                ->select();
            foreach ($lists as $key=>&$vo){
                if($vo['good_type']==1){
                    $vo['price_a'] = $vo['good_price'];
                }elseif ($vo['good_type']==2){
                    $vo['price_a'] = $vo['good_y_price'];
                }

            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch();
    }
    /***
     * 班级成员
     */
    public function classed(){

        if(request()->isAjax()){
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
           $info = Db::table('up_grade_class')->where('gs_user_id',input('id'))->select();

           $school = implode(',',array_filter(array_column($info,'gs_school_id')));
           $gs_grade_id = implode(',',array_filter(array_column($info,'gs_grade_id')));
           $gs_class_id = implode(',',array_filter(array_column($info,'gs_class_id')));
            $where['gs_school_id'] = array('IN',$school);
            $where['gs_grade_id'] = array('IN',$gs_grade_id);
            $where['gs_class_id'] = array('IN',$gs_class_id);
            $count = Db::name('grade_class')->where($where)->count();// 获取总条数
            $lists = Db::name('grade_class')
                ->join('up_u_user', 'gs_user_id = user_id', 'left')
                ->field('user_id, user_username, user_time,user_gender,user_nickname,user_exp')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('user_time asc')
                ->select();
            foreach ($lists as $key=>&$vo){
                if($vo['user_gender']==1){
                    $vo['gender'] = '男';
                }else{
                    $vo['gender'] = '女';
                }
                //查询段位
                $level = Db::table('up_exp_level')
                    ->where('el_min','<=',$vo['user_exp'])
                    ->order('el_level DESC')
                    ->find();
                $vo['level'] = $level['el_name'];
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch();
    }

    public function order(){
        if(request()->isAjax()){
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $where['order_userid'] = input('param.id');
            $where['order_status'] = array('IN',array(1,2,3,4));
            $count = Db::table('up_order')->where($where)->count();
            $lists = Db::name('order')->alias('a')
                ->page($Nowpage,$limits)
                ->where($where)
                ->select();
            foreach ($lists as $key=>&$vo){
                if($vo['order_status']==1){
                   $vo['order_status_name'] = '未支付';
                }elseif ($vo['order_status']==2){
                    $vo['order_status_name'] = '代发货';
                }   elseif ($vo['order_status']==3){
                    $vo['order_status_name'] = '待收货';
                }  elseif ($vo['order_status']==4){
                    $vo['order_status_name'] = '已收货';
                }
                if($vo['order_hh_payment']==2){
                    $vo['order_type_name'] = '金币支付';
                }else{
                    if($vo['order_type']==1){
                        $vo['order_type_name'] = '支付宝';
                    }elseif ($vo['order_type']==2){
                        $vo['order_type_name'] = '微信';
                    }
                }

                if($vo['order_is_coupon']==1){//证明使用优惠卷了
                    $coupon_name = Db::table('up_my_coupon')->alias('a')
                         ->join('up_coupon uc','uc.coupon_id = a.mc_coupon_id')
                         ->field('uc.coupon_name')
                         ->where('a.mc_id',$vo['order_my_coupon'])
                         ->find();
                    $vo['coupon_name'] = $coupon_name['coupon_name'];
                }else{
                    $vo['coupon_name'] = '';
                }
                $good_name = Db::table('up_order_info')->alias('b')
                        ->join('up_goods ug','ug.good_id = b.oi_good_id')
                        ->where('b.oi_order_id',$vo['order_id'])
                        ->field('ug.good_id,ug.good_name')
                        ->select();
                $vo['good_name'] = implode(',',array_column($good_name,'good_name'));//切割商品名称
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $id = input('id');
        if($id != ''){
            session('user_id1',$id);
        }
        return $this->fetch();
    }
}